package study;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Function;

/**
 * @Author 金贵权
 * @Date 2023/6/9 17:23
 **/
public class Utils {
    public static List<User> getUserList(){
        List<User> list = new ArrayList<>();
        list.add(new User(1,"李四"));
        list.add(new User(2,"张三"));
        list.add(new User(2,"赵六"));
        list.add(new User(3,"王五"));
        list.add(new User(4,"李四"));
        list.add(new User(5,"刘鑫"));
        return list;
    }

    public static List<User> getAnyUserList(int size){
        List<User> list = new LinkedList<>();
        List<String> nameList = Arrays.asList("李四", "李四", "张三", "赵六", "王五", "李四", "刘鑫");
        for (int i = 1; i <= size; i++) {
            list.add(new User(i,nameList.get((int)(Math.random()*7))));
        }
        return list;
    }

    public static long measureSumPerf(Function<Long,Long> adder,long n){
        long faster = Long.MAX_VALUE;
        for (int i = 0; i < 10; i++) {
            long start = System.nanoTime();
            long sum = adder.apply(n);
            long duration = (System.nanoTime() - start)/1_000_000;
            System.out.println("Result:" + sum);
            if(duration < faster) faster = duration;
        }
        return faster;
    }
}
